<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function ouputcsv()
{
	$("#if_csv").val(1);
	$("#search").submit();
}
function showaddmaterial()
{
	$("#projeck").val("");
	$("#code").val("");
	$("#cangwei").val("");
	$("#colores").val("");
	$("#type").val("");
	//类别
	$("#type2").hide();
	$("#type").val("");
	$("#typename").val("");
	//供应商
	$("#type4").hide();
	$("#supplier").val("");
	$("#suppliersearch").val("");
	$("#num").val("");
	$("#price").val("");
	$("#dw").val("");
	$("#descr").val("");

	$("#material_id").val("");
	$('#showaddmaterialfrom').modal('show');	
}
function chumaterial()
{
	$('#chumaterial').modal('show');		
}
function ontype()
{
	if( $("#type1").css("display")=='none' )
	{
		$("#type1").show();
		$("#type2").hide();
	}else{
		$("#type2").show();
		$("#type1").hide();	
	}
}
function ontypetwo()
{
	if( $("#type3").css("display")=='none' )
	{
		$("#type3").show();
		$("#type4").hide();
	}else{
		$("#type4").show();
		$("#type3").hide();	
	}
}
function chuku()
{
	var c_code = $("#c_code").val();
	if(c_code=="")
	{
		alert("请填写出库物料编号！");
		return;	
	}
	var c_num = $("#c_num").val();
	if(c_num=='')
	{
		alert('请输入出库数量！');
		return;
		}
	var c_memo = $("#c_memo").val();
	if( c_memo =='')
	{
		alert("请填写出库描述！");
		return;	
	}
  $.post("/factory/ajaxbutton", {"op": "getmaterialcode","c_code":c_code,"c_num":c_num},
  function(data){
		if(data==201)
		{
			alert("不存在该物料编号！请重新输入！");
			return;	
		}
		if(data==202)
		{
			alert("在库数小于你要出库数！请重新输入数量！");
			return;	
		}
   },"text");
   
    $.post("/factory/ajaxbutton", {"op": "savematerchuk","c_code":c_code,"c_num":c_num,"c_memo":c_memo},
  function(data){
		if(data==200)
		{
			window.location.href = "/factory/material";	
		}
   },"text");
			
}
function atmangban()
{
	var projeck = $("#projeck").val();
	if(projeck=="")
	{
		alert("请物料名称！");
		return;	
	}
	var code = $("#code").val();
	if(code=='')
	{
		alert('请输入编号！');
		return;
		}
	var type = $("#type").val();
	var typename = $("#typename").val();
	if(type=="" && typename =='')
	{
		alert("请选择类别！");
		return;	
	}
	
	var suppliersearch = $("#suppliersearch").val();
	var supplier = $("#supplier").val();
	if(suppliersearch=="" &&　supplier=='')
	{
		alert("请选择供应商！");
		return;	
	}
	var num = $("#num").val();
	var price = $("#price").val();
	var dw = $("#dw").val();
	if(num=="" || price=='' || dw =='')
	{
		alert("数量、单位、单价必须填写！");
		return;	
	}
	var descr = $("#descr").val();
	var editid = $("#editid").val();
	var colores = $("#colores").val();
	var cangwei = $("#cangwei").val();
	//修改时的material_id
	var material_id = $("#material_id").val();
	
	$.post("/factory/ajaxbutton", {"op": "savematerial","projeck":projeck,"type":type,"code":code,"typename":typename,"price":price,"num":num,"descr":descr,"suppliersearch":suppliersearch,"supplier":supplier,"dw":dw,"editid":editid,"colores":colores,"cangwei":cangwei,"material_id":material_id},
	  function(data){
			if(data==200)
			{
				window.location.href = "/factory/material";	
			}
	   },"text");
}
function showimages(id,t,s)
{
	$.post("/externalBuy/ajaxbutton", {"op": "showImages","id":id,"type":1},
			function(data){
				if(data)
				{
					var tmp="<div class=upload_preview>";
					for(var i=0;i<data.length;i++)
					{
						if(s==1)
						{
							var dels= "<div class=\"delnocss\" style='right:-15px;'><a href=\"#\" title=\"删除图片\"><img src=\"/fuman/images/no.gif\" onclick=\"delone("+data[i].id+",'externalbuy',0)\"></a></div>";
						}else{
							var dels="";
						}
						tmp+=" <div style='border:1px;width:90px;  margin: 1em;float: left;position: relative;'><a href="+data[i].images_url+" target=_thank><img src='"+data[i].thumb_url+"' style=\"width:expression(this.width > 85 ? 85px : this.width)\"></a>"+dels+"</div>";
					}
					$("#uidvalue").val(id);
					tmp+="</div>";
					$("#showimages").html(tmp);
				}

			},"json");
	$("#MergeProductID").val(id);
	if(t==1)
	{
		$("#zyupload").hide();
	}else{
		$("#zyupload").show();
	}
	$('#showimagesform').modal('show');

}
/******全站ajax button****/
function delone(id,t,v)
{
	if(v == 1){
		var message = "确定移除所有图片？";
	}else{
		var message = "确定移除?"
	}
	if(confirm(message))
	{
		$.post("/externalBuy/ajaxbutton", {"op": "delone","id":id,"st":t,"delflag":v,"type":1},
				function(data){
					if(data.txt==200)
					{
						//document.location.href = data.url;
						location.reload();
						return;
					}

					if(data.txt==201)
					{
						alert(data.text);
						return ;
					}

					return;
				},"json");
	}
}
	function updData(id,status) {
		if(status==1){ //删除
			if(confirm("确定删除这条数据？"))
			{
				$.post("/factory/ajaxbutton", {"op": "updMaterialData","id":id,"status":1},
						function(data){
							if(data==200)
							{
								location.reload();
								return;
							}
							return;
						},"json");
			}

		}
		if(status==2){ //编辑
			$.post("/factory/ajaxbutton", {"op": "updMaterialData","id":id,"status":2},
					function(data){
						if(data)
						{
							$("#projeck").val(data.projeck);
							$("#code").val(data.code);
							$("#cangwei").val(data.cangwei);
							$("#colores").val(data.colores);
							//$("#type").val(data.type);
							//类别
							$("#type2").show();
							$("#typename").val(data.typename);
							//供应商
							$("#type4").show();
							$("#suppliersearch").val(data.supplier);
							$("#num").val(data.num);
							$("#price").val(data.price);
							$("#dw").val(data.dw);
							$("#descr").val(data.descr);

							$("#material_id").val(data.id);

							//location.reload();
							//return;
						}
						return;
					},"json");

			$('#showaddmaterialfrom').modal('show');


		}
		
	}
</script>
<title>工厂物料管理列表</title>
<body class="withvernav">
<div class="bodywrapper">
<div class="centercontent">
<div class="pageheader notab">
  <h1 class="pagetitle">工厂物料管理列表</h1>
  <span class="pagedesc"></span>
  <div class="menulist">
    <ul class="profile_summary">
       <li {{if $status==""}} class="current"{{/if}}> <a href="javascript:void(0)" onClick="showaddmaterial()"><span>添加物料信息</span></a></li>
        <li> <a href="javascript:void(0)" onClick="chumaterial()"><span>物料出库</span></a></li>
      
       </ul>
  </div>
</div>
<!--pageheader-->
<div id="contentwrapper" class="contentwrapper">
  <div id="basicform" class="subcontent"> 
    <!--搜索栏-->
    <div>
      <div style="clear: both"></div>
      <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
    </div>
    <form class="stdform stdform2" method="get" id="search" action="/factory/material">
     <div class="tableoptions"> 
        &nbsp;
         编号: <input type="text" name="other" id="other" class="width200" value="{{$other}}" placeholder="物料编号或名称" />
       
        
        <button class="btn btn-primary" id="searchbtn">Search</button>
       </div>
    </form>
    <!--搜索栏结束-->
    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" style="table-layout: fixed;">
      <thead>
        <tr class="lbbt">
          <td bgcolor="#FEFFF1">物料编号</td>
	        <td bgcolor="#FEFFF1">图片</td>
          <td bgcolor="#FEFFF1">物料名称</td>
          <td bgcolor="#FEFFF1">类别</td>
          <td bgcolor="#FEFFF1">供应商</td>
          <td bgcolor="#FEFFF1">数量</td>
          <td bgcolor="#FEFFF1">单价</td>
          <td bgcolor="#FEFFF1">颜色</td>
          <td bgcolor="#FEFFF1">仓位</td>
          <td bgcolor="#FEFFF1">备注</td>
	        <td bgcolor="#FEFFF1">样本链接</td>
         <td bgcolor="#FEFFF1" width="12%">明细</td>
        </tr>
      </thead>
      <tbody >
      
      {{foreach from=$orderlist item=li key=key}}
      <tr>
        <td valign="middle"  style="position:relative;">{{$li.code}}</td>
	      <td valign="middle">
		      {{if $li.mod==1}}
		      <a href="javascript:void(0)" onClick="showimages({{$li.id}},1,1)"><img src="{{$li.images}}" width="50"></a>
		      {{else}}
		      <a href="javascript:void(0)" onClick="showimages({{$li.id}},1,0)"><img src="{{$li.images}}" width="50"></a>
		      {{/if}}
	      </td>
        <td valign="middle" >{{$li.projeck}}</td>
         <td valign="middle" >{{$li.typename}}</td>
         <td valign="middle" >{{$li.supplier}}</td>
        <td   style="position:relative;">{{$li.num}}{{$li.dw}}
        
        </td>
        <td valign="middle" >{{$li.price}}</td>
        
        <td valign="middle" >{{$li.colores}}</td>
        <td valign="middle" >{{$li.cangwei}}</td>
        <td>
        {{if $managers || $userclassid ==11}}
        <span style="cursor:pointer" onClick="listTable.edit(this, 'factorymaterialmark','{{$li.id}}','{{$li.descr}}')">{{if $li.descr}}{{$li.descr}}{{else}}<font color="#CCCCCC">编辑备注</font>{{/if}}</span>
        {{else}}
        {{$li.descr}}
        {{/if}}
        </td>
	      <td>
		      {{if $li.mod==1}}
		        <a href="javascript:void(0)" onClick="showimages({{$li.id}},0,1)">样本图</a>
		      {{else}}
		        <a href="javascript:void(0)" onClick="showimages({{$li.id}},0,0)">样本图</a>
		      {{/if}}
	      </td>
         <td>
	         {{if $managers || $li.oper eq $username || $li.factoryid eq $userclassid}}
	            <a href="javascript:void(0);" onClick="updData('{{$li.id}}',2);"> <button class="stdbtn">编辑</button></a>&nbsp;&nbsp;
	         {{/if}}
	         {{if $managers || $li.oper eq $username || $li.factoryid eq $userclassid}}
	                <a href="javascript:void(0);" onClick="updData('{{$li.id}}',1);"> <button class="stdbtn">删除</button></a>&nbsp;&nbsp;
	         {{/if}}
	         <a href="/factory/ajaxbutton?op=showmaterial&code={{$li.code}}" target="_blank">明细</a>
         </td>
      </tr>
     
      {{/foreach}}
     
        </tbody>
      
    </table>
    <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
  </div>
</div>


<form  method="post">
  <input type="hidden" name="editid" id="editid">
  <div class="modal fade" id="chumaterial" tabindex="-1" role="dialog" aria-labelledby="schumaterial" aria-hidden="true">
    <div class="modal-dialog" style="width:740px;">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" 
               aria-hidden="true">× </button>
          <h4 class="modal-title" id="chuaddmaterialfrom"> 物料出库 </h4>
        </div>
        <div class="modal-body">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="100" align="right">物料编号： </td>
              <td align="left"><input type="text" name="c_code" id="c_code">
                <font color="#FF0000">(*必选项)</font></td>
            </tr>
             <tr>
              <td width="100" align="right">出库数量： </td>
              <td align="left"><input type="text" name="c_num" id="c_num" onkeyup="value=value.replace(/[^\d.]/g,'')">
                <font color="#FF0000">(*必选项)</font></td>
            </tr>
          
          <tr>
              <td width="100" align="right">描述： </td>
              <td align="left"><input type="text" name="c_memo" id="c_memo">
                <font color="#FF0000">(*必选项)</font></td>
            </tr>
          
           
          </table>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal"> 关闭 </button>
            <button type="button" class="btn btn-primary"  onclick="chuku()"> 提交 </button>
          </div>
        </div>
        <!-- /.modal-content --> 
      </div>
      <!-- /.modal-dialog --> 
    </div>
  </div>
  <!-- /.modal -->
</form>

<!-- 模态框（Modal）添加支出 -->
<form  method="post">
  <input type="hidden" name="material_id" id="material_id" value="100">
  <div class="modal fade" id="showaddmaterialfrom" tabindex="-1" role="dialog" aria-labelledby="sshowaddmaterialfrom" aria-hidden="true">
    <div class="modal-dialog" style="width:740px;">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" 
               aria-hidden="true">× </button>
          <h4 class="modal-title" id="showaddmaterialfrom"> 添加物料信息 </h4>
        </div>
        <div class="modal-body">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="100" align="right">物料名称： </td>
              <td align="left"><input type="text" name="projeck" id="projeck">
                <font color="#FF0000">(*必选项)</font></td>
            </tr>
	          <tr>
              <td width="100" align="right">编号： </td>
              <td align="left">
	              <input type="text" name="code" id="code" class="width100" style="padding-bottom: 0em;">
                <font color="#FF0000" style="margin-left: 150px;">(*必选项，编号相同的物料，入库数量会合并)</font>
              </td>
	          </tr>
            <tr>
              <td align="right" >仓位</td>
              <td align="left"><input type="text" name="cangwei" id="cangwei"></td>
            </tr>
            <tr>
              <td align="right" >颜色</td>
              <td align="left"><input type="text" name="colores" id="colores"></td>
            </tr>
            <tr>
              <td width="100" align="right" >类别： </td>
              <td align="left">
              	<span id="type1" style="">
              	<select id="type" name="type" class="small_input">
                  <option value="">-请选择类别-</option>
                  {{foreach from=$newtype item=li key=key}}
                  <option   value="{{$li}}">{{$li}}</option>
                  {{/foreach}}
                </select>
                </span>
                <span id="type2" style="display:none">
                	 <input id="typename" type="text" value="" class="dfinput" value="typename" style="width: 120pt;height: 20pt;" placeholder="请输入类别名称"/>
                </span>
                &nbsp;&nbsp;<a href="javascript:void(0)" onClick="ontype()">添加类别</a></td>
            </tr>
             <tr >
              <td  align="right">供应商：</td>
              <td  align="left">

              <span id="type3" style="">
              	<select id="supplier" name="supplier" class="small_input">
                  <option value="">-请选择供应商-</option>
                   {{foreach from=$newsupplier item=li key=key}}
                  <option   value="{{$li}}">{{$li}}</option>
                  {{/foreach}}
                </select>
                </span>
                <span id="type4" style="display:none">
                    <input id="suppliersearch" type="text" value="" class="dfinput" style="width: 120pt;height: 20pt;" placeholder="请输入供应商名称"/>
                </span>
                &nbsp;&nbsp;<a href="javascript:void(0)" onClick="ontypetwo()">添加供应商</a>
              
            </td>
            </tr>
             <tr>
              <td align="right">数量： </td>
              <td align="left"><input type="text" name="num" id="num" value="1" maxlength="200" style="width:100px;line-height:0.4;" class="small_input" /><font color="#FF0000">(*必选项)</font></td>
            </tr>
            <tr>
              <td  align="right">单价： </td>
              <td align="left"><input type="text" name="price" id="price" value="" maxlength="200" style="width:100px;line-height:0.4;" class="small_input" /><font color="#FF0000">(*必选项)</font></td>
            </tr>
           <tr>
              <td  align="right">单位： </td>
              <td align="left"><input type="text" name="dw" id="dw" value="" maxlength="200" style="width:100px;line-height:0.4;" class="small_input" /> <button onclick="document.getElementById('dw').value='个'" type="button">个</button>
              	<button onclick="document.getElementById('dw').value='米'" type="button">米</button>
                <button onclick="document.getElementById('dw').value='根'" type="button">根</button>
                <button onclick="document.getElementById('dw').value='块'" type="button">块</button><font color="#FF0000">(*必选项)</font></td>
            </tr>
            <tr>
              <td  align="right">描述：</td>
              <td  align="left"><textarea  class="full_input" name="descr" id="descr" cols="10" rows="5"></textarea></td>
            </tr>
           
          </table>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal"> 关闭 </button>
            <button type="button" class="btn btn-primary"  onclick="atmangban()"> 提交 </button>
          </div>
        </div>
        <!-- /.modal-content --> 
      </div>
      <!-- /.modal-dialog --> 
    </div>
  </div>
  <!-- /.modal -->
</form>

	<!-- 模态框（Modal） 样本图片-->
	<form action="/factory/ajaxbutton?op=saveProductImages"  method="post" name="uctsform" id="uctsform" >
		<input type="hidden" name="MergeProductID" id="MergeProductID">
		<input type="hidden" value="0" name="uidvalue" id="uidvalue">
		<div class="modal fade" id="showimagesform" tabindex="-1" role="dialog" aria-labelledby="sshowimagesform" aria-hidden="true">
			<div class="modal-dialog" style="width:740px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
						        aria-hidden="true">× </button>
						<h4 class="modal-title" id="sshowimagesform">样本图&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <a href="javascript:void(0);" onClick="delone($('#uidvalue').val(),'externalbuy',1)">移除所有图片</a> </h4>
					</div>
					<div class="modal-body">
						<div style="width:100%;height:400px; overflow-y:scroll; border:0px solid;">
							<div id="showimages"></div>
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td>
										<link rel="stylesheet" href="/fuman/upfile/uploadify/zyupload/skins/zyupload-1.0.0.min.css" type="text/css">
										<script type="text/javascript" src="/fuman/upfile/uploadify/zyupload/zyupload.basic-1.0.0.min.js"></script>
										<div id="upok"></div>
										<div id="zyupload" class="zyupload"></div>
										<div id="uploadInfnew"></div>

										<script type="text/javascript">
											$(function(){
												// 初始化插件
												$("#zyupload").zyUpload({
													width            :   "650px",                 // 宽度
													height           :   "400px",                 // 宽度
													itemWidth        :   "100px",                 // 文件项的宽度
													itemHeight       :   "95px",                 // 文件项的高度
													url              :   "/fuman/upfile/uploadify/up.php",              // 上传文件的路径
													fileType         :   ["jpg","png","txt","js","exe","JPG","PNG"],// 上传文件的类型
													fileSize         :   51200000,                // 上传文件的大小
													multiple         :   true,                    // 是否可以多个文件上传
													dragDrop         :   false,                   // 是否可以拖动上传文件
													tailor           :   false,                   // 是否可以裁剪图片
													del              :   true,                    // 是否可以删除文件
													finishDel        :   false,  				  // 是否在上传文件完成后删除预览
													/* 外部获得的回调接口 */
													onSelect: function(selectFiles, allFiles){    // 选择文件的回调方法  selectFile:当前选中的文件  allFiles:还没上传的全部文件
														console.info("当前选择了以下文件：");
														console.info(selectFiles);
													},
													onDelete: function(file, files){              // 删除一个文件的回调方法 file:当前删除的文件  files:删除之后的文件
														console.info("当前删除了此文件：");
														console.info(file.name);
													},
													onSuccess: function(file, response){          // 文件上传成功的回调方法
														console.info("此文件上传成功：");
														console.info(file.name);
														console.info("此文件上传到服务器地址：");
														console.info(response);
														//$("#uploadInf").append("<p>上传成功，文件地址是：" + response + "</p>");
														$("#uploadInfnew").append( response );
														$("#upok").html("<p><h1>上传成功，点击提交,保存图片</h1></p>");
													},
													onFailure: function(file, response){          // 文件上传失败的回调方法
														$("#uploadInf").append("<p>此文件上传失败：" + file.name + "</p>");
													},
													onComplete: function(response){           	  // 上传完成的回调方法
														console.info("文件上传完成");
														console.info(response);
													}
												});

											});

										</script>
									</td>
								</tr>

							</table>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default"
							        data-dismiss="modal"> 关闭 </button>
							<button type="button" class="btn btn-primary"  onclick="AWSsubmit('uctsform','showimagesform')"> 提交 </button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal-dialog -->
			</div>
		</div>
	</form>
	<!-- 模态框（Modal）样本图片 -->
</body>
</html>